<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import { getUrlParam, setToken, setRefreshToken, removeRefreshToken, getSchoolCode, setSchoolCode, setSchoolName } from '@/utils'
export default {
  name: 'App',
  created() {
    const {
      dispatch,
      state: { common }
    } = this;
    removeRefreshToken()
    const token = getUrlParam('token');
    if (!token) {
      return alert('token字段缺失，请联系管理员')
    }
    if (token) {
      window.appToken = token
      setToken(token);
    }
    const schoolCode = getSchoolCode();
    if (!schoolCode) {
      dispatch('common/getUserInfo').then(() => {
        const { userInfoSource } = common;
        if (userInfoSource) {
          setSchoolCode(userInfoSource.schoolCode);
          setSchoolName(userInfoSource.schoolName);
        }
      })
    }
    window.addEventListener('message', (e) => {
      // console.log('接收数据message---------------------', e);
      // console.log('接收数据data-------------------------', e.data);
      if (e.data.name === 'Event_refreshToken') {
        const data = JSON.parse(e.data);
        setRefreshToken(data.data);
      }
    })
  }
}
</script>

<style lang="scss">
#app {
  height: 100%;
  .el-dialog__header {
    text-align: left;
    padding-top: 10px;
    background-color: #eaedf1;
    .el-dialog__title {
      color: #333;
      font-weight: 700;
      font-size: 14px;
    }
  }
  element.style {
    padding-left: 40px;
    color: rgb(51, 51, 51);
    background-color: #2b2828;
  }
  .el-dialog__headerbtn {
    font-size: 20px;
    margin-top: -10px;
  }
  .el-dialog__footer {
    text-align: center;
    padding-top: 20px;
  }
}
.el-header {
  height: 50px !important;
  padding: 0;
  background: linear-gradient(
    90deg,
    #c7091f 0%,
    #e40922 49%,
    #ed560b 97%,
    #ed560b 100%
  );
  color: #fff;
  text-align: left;
  font-size: 12px;
}
.el-aside {
  transition: all 0.5s;
  background-color: #2b2828;
  overflow-x: hidden !important;
}
.el-menu {
  border-right: 0 !important;
  transition: all 0.5s;
  background-color: #2b2828;
}
</style>
